package com.zzy.service.impl;

import com.zzy.annotation.Autowired;
import com.zzy.annotation.Service;
import com.zzy.annotation.Transactional;
import com.zzy.dao.impl.JdbcAccountDaoImpl;
import com.zzy.pojo.Account;
import com.zzy.service.TransferService;

@Service
public class  TransferServiceImpl implements TransferService {

    @Autowired
    private JdbcAccountDaoImpl accountDao;

    @Override
    @Transactional
    public void transfer(String fromCardNo, String toCardNo, int money) throws Exception {

            Account from = accountDao.queryAccountByCardNo(fromCardNo);
            Account to = accountDao.queryAccountByCardNo(toCardNo);

            from.setMoney(from.getMoney()-money);
            to.setMoney(to.getMoney()+money);

            accountDao.updateAccountByCardNo(to);
            int c = 1/0;
            accountDao.updateAccountByCardNo(from);

    }
}
